package com.qianfeng.zhangwei.fruitday;

import android.app.Application;

import com.lidroid.xutils.bitmap.BitmapGlobalConfig;
import com.lidroid.xutils.cache.MD5FileNameGenerator;
import com.qianfeng.zhangwei.fruitday.config.AppConfig;
import com.qianfeng.zhangwei.fruitday.netstate.NetChangeObserver;
import com.qianfeng.zhangwei.fruitday.netstate.NetworkStateReceiver;
import com.qianfeng.zhangwei.fruitday.utils.AppNetChangeObserver;
import com.qianfeng.zhangwei.fruitday.utils.SuperToastUtils;

import org.androidannotations.annotations.EApplication;

/**
 * @说 明：
 * @项目名称：Sz1504Adv
 * @包 名： com.qianfeng.zhangwei.fruitday
 * @类 名： BaseApp
 * @创 建人： zhangwei
 * @创建时间：2015-08-04 17:37
 * @版 本：v1.0
 * @修 改人：
 * @修改时间：
 * @修改备注：
 *
 *
 */
@EApplication
public class BaseApp extends Application {
    private AppNetChangeObserver observer = new AppNetChangeObserver();

    @Override
    public void onCreate() {
        super.onCreate();
        //注册网络监听
        registerNetState();
        //初始化全局toast工具类
        SuperToastUtils.init(this);
        initBitmapGolbalConfig();

    }


    /**
     * 图片框架全局配置
     */
    private void initBitmapGolbalConfig() {
        BitmapGlobalConfig config = BitmapGlobalConfig.getInstance(this, AppConfig.APP_CACHE + AppConfig.IMAGE_CACHE);
        config.setFileNameGenerator(new MD5FileNameGenerator());
    }


    /**
     * 注册网络状态监听
     */
    private void registerNetState() {
        NetworkStateReceiver.registerNetworkStateReceiver(this);
        NetworkStateReceiver.registerObserver(new NetChangeObserver());
    }

    /**
     * 注销网络状态监听
     */
    public void unregisterNetworkStateReceiver() {
        NetworkStateReceiver.unRegisterNetworkStateReceiver(this);
        NetworkStateReceiver.removeRegisterObserver(observer);
    }


}
